package com.hsnn.medstgmini.trading.pur.service.impl;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.trading.pur.dao.CreateOrderDao;
import com.hsnn.medstgmini.trading.pur.model.form.CreateOrderForm;
import com.hsnn.medstgmini.trading.pur.service.CreateOrderManager;

/**
 * @category 医疗机构生成订单
 * @author 蔡春龙
 * @date 2015年7月8日
 */
@Service
public class CreateOrderManagerImpl implements CreateOrderManager {

	@Autowired
	private CreateOrderDao createOrderDao;
	
	@Resource(name = "sessionFactory")
	private SessionFactory factory; 
	
	/**
	 * @category 提交订单
	 * @date 2015年7月10日
	 * @param orderForm
	 * @return
	 */
	@Transactional
	public void submitOrder(CreateOrderForm orderForm, SysUser user) {
		Session session = factory.getCurrentSession();
		Transaction tran = session.getTransaction();
		try {
			tran.begin();
			createOrderDao.submitOrder(orderForm, user);
			tran.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tran.rollback();
		}
	}

}
